package io.gitee.yth.design.pattern.test.core.pattern.behavioral.command;

import org.junit.jupiter.api.Test;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.command.light.LightOffCommand;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.command.light.LightOnCommand;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.command.light.LightReceiver;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.command.tv.TVOffCommand;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.command.tv.TVOnCommand;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.command.tv.TVReceiver;

/**
 * @author yth
 * @since 2023-04-29-0:14
 */
public class Client {
    @Test
    public void test1() {
        final RemoteControl control = new RemoteControl(5);

        final LightReceiver lightReceiver = new LightReceiver();
        final Command lightOnCommand = new LightOnCommand(lightReceiver);
        final Command lightOffCommand = new LightOffCommand(lightReceiver);

        final TVReceiver tvReceiver = new TVReceiver();
        final TVOnCommand tvOnCommand = new TVOnCommand(tvReceiver);
        final TVOffCommand tvOffCommand = new TVOffCommand(tvReceiver);

        control.setCommand(0, lightOnCommand, lightOffCommand);
        control.setCommand(1, tvOnCommand, tvOffCommand);

        control.invokeOnCommand(0);
        control.invokeOnCommand(1);
        control.invokeOffCommand(0);
        control.undoCommand();

        System.out.println("light is on = " + lightReceiver.isOn());
        System.out.println("tv is on = " + tvReceiver.isOn());
    }

    @Test
    public void test2() throws NoSuchMethodException {
        final LightReceiver lightReceiver = new LightReceiver();
        final Command command = new SimpleCommand<>(lightReceiver, "on");
        command.execute();
    }

    @Test
    public void test3() {
        final LightReceiver lightReceiver = new LightReceiver();
        final Command lightOnCommand = new LightOnCommand(lightReceiver);

        final TVReceiver tvReceiver = new TVReceiver();
        final TVOnCommand tvOnCommand = new TVOnCommand(tvReceiver);

        final MacroCommand macroCommand = new MacroCommand();
        macroCommand.add(lightOnCommand);
        macroCommand.add(tvOnCommand);
        macroCommand.execute();
        macroCommand.undo();
    }

}
